package cn.ipenta.blockchain;

import java.io.IOException;
import java.net.URISyntaxException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import cn.ipenta.blockchain.repo.BlockChainClient;
import hprose.client.HproseClient;

/** 
* @ClassName: BlockChainBeanRegister 
* @Description: TODO
* @author ipenta
* @date 2017年3月28日 下午3:15:20 
*  
*/
@Component
public class BlockChainBeanRegister {

	@Autowired
	private PropertiesConfigurator propertiesConfigurator;

	@Bean
	public HproseClient createHproseClient() {
		HproseClient hproseClient = null;
		try {
			hproseClient = HproseClient.create(propertiesConfigurator.getUrl());
		} catch (IOException | URISyntaxException e) {
			throw new BlockChainException(e);
		}
		return hproseClient;
	}
	
	@Bean
	public BlockChainClient createBlockChainProvider() {
		HproseClient hproseClient = null;
		try {
			hproseClient = HproseClient.create(propertiesConfigurator.getUrl());
		} catch (IOException | URISyntaxException e) {
			throw new BlockChainException(e);
		}
		return hproseClient.useService(BlockChainClient.class);
	}
}
